package com.eqdd.yiqidian.ui.yiqixue.info;

import android.databinding.DataBindingUtil;

import com.eqdd.yiqidian.LearnArticleInfoActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.utils.ClickUtil;
import com.eqdd.yiqidian.utils.ImageUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * @author吕志豪 .
 * @date 18-3-10  上午11:28.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class LearnArticleInfoActivity extends BaseActivity {

    private LearnArticleInfoActivityCustom dataBinding;
    private int id;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_learn_article_info);
        id = getIntent().getIntExtra(Config.ID, 0);
        ClickUtil.click(dataBinding.ivBack, this::onBackPressed);

    }

    @Override
    public void initData() {
        dataBinding.richEditor.setInputEnabled(false);
        dataBinding.richEditor.setPadding(15, 15, 15, 15);
    }

    @Override
    public void setView() {

        OkGo.<HttpResult<LearnArticleInfoBean>>post(HttpConfig.BASE_URL + HttpConfig.LEARN_ARTICLE_INFO)
                .params("lectureArticleId", id)
                .execute(new DialogCallBack<HttpResult<LearnArticleInfoBean>>(LearnArticleInfoActivity.this) {
                    @Override
                    public void onSuccess(Response<HttpResult<LearnArticleInfoBean>> response) {
                        HttpResult<LearnArticleInfoBean> httpResult = response.body();
                        if (httpResult.getStatus() == 200) {
                            refreshView(httpResult.getItems());
                        }
                    }
                });


    }

    private void refreshView(LearnArticleInfoBean items) {
        ImageUtil.setCircleImage(items.getIphoto(), dataBinding.ivHead);
        dataBinding.tvNameTop.setText(items.getStaffName());
        ImageUtil.setCircleImage(items.getIphoto(), dataBinding.ivHeadArticle);
        dataBinding.tvNameArticle.setText(items.getStaffName());
        dataBinding.tvTitle.setText(items.getTitle());
        String html = items.getContent().replace("<pre>", "").replace("</pre>", "");
        dataBinding.richEditor.setHtml(html);
        dataBinding.tvArticleInfo.setText("阅读量:" + items.getBrowseCount() + "人");
    }

    public class LearnArticleInfoBean {


        /**
         * Id : 1
         * lectureId : 0
         * userGuid : 1221b0fed5ec43d88e6b0d5a08e50e79
         * createTime : 2018-01-06T17:05:33.483
         * title : 标题
         * content : <p><img src="https://www.eqid.top:8009/image/20171221/upload/17122111152945252.png" style="max-width:100%;"><br></p><p>测试</p>
         * homeImage : https://www.eqid.top:8009/image/20171221/upload/17122111152945252.png
         * Label : 标签
         * browseCount : 1
         * commentCount : 0
         * zanCount : 0
         * companyId : 14
         * collectionCount : 0
         * reprintCount : 0
         * status : 0
         * boutique : false
         * hot : false
         * reportCount : 0
         * textContent : 啥答案 打
         * iphoto : https://www.eqid.top:8009/image/20171107/15690783806/20171107025759headimage.png
         * uname : 15690783806
         * upname : 路飞
         * staffName : 闫浩杰
         */

        private int Id;
        private int lectureId;
        private String userGuid;
        private String createTime;
        private String title;
        private String content;
        private String homeImage;
        private String Label;
        private int browseCount;
        private int commentCount;
        private int zanCount;
        private int companyId;
        private int collectionCount;
        private int reprintCount;
        private int status;
        private boolean boutique;
        private boolean hot;
        private int reportCount;
        private String textContent;
        private String iphoto;
        private String uname;
        private String upname;
        private String staffName;

        public int getId() {
            return Id;
        }

        public void setId(int Id) {
            this.Id = Id;
        }

        public int getLectureId() {
            return lectureId;
        }

        public void setLectureId(int lectureId) {
            this.lectureId = lectureId;
        }

        public String getUserGuid() {
            return userGuid;
        }

        public void setUserGuid(String userGuid) {
            this.userGuid = userGuid;
        }

        public String getCreateTime() {
            return createTime;
        }

        public void setCreateTime(String createTime) {
            this.createTime = createTime;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public String getHomeImage() {
            return homeImage;
        }

        public void setHomeImage(String homeImage) {
            this.homeImage = homeImage;
        }

        public String getLabel() {
            return Label;
        }

        public void setLabel(String Label) {
            this.Label = Label;
        }

        public int getBrowseCount() {
            return browseCount;
        }

        public void setBrowseCount(int browseCount) {
            this.browseCount = browseCount;
        }

        public int getCommentCount() {
            return commentCount;
        }

        public void setCommentCount(int commentCount) {
            this.commentCount = commentCount;
        }

        public int getZanCount() {
            return zanCount;
        }

        public void setZanCount(int zanCount) {
            this.zanCount = zanCount;
        }

        public int getCompanyId() {
            return companyId;
        }

        public void setCompanyId(int companyId) {
            this.companyId = companyId;
        }

        public int getCollectionCount() {
            return collectionCount;
        }

        public void setCollectionCount(int collectionCount) {
            this.collectionCount = collectionCount;
        }

        public int getReprintCount() {
            return reprintCount;
        }

        public void setReprintCount(int reprintCount) {
            this.reprintCount = reprintCount;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public boolean isBoutique() {
            return boutique;
        }

        public void setBoutique(boolean boutique) {
            this.boutique = boutique;
        }

        public boolean isHot() {
            return hot;
        }

        public void setHot(boolean hot) {
            this.hot = hot;
        }

        public int getReportCount() {
            return reportCount;
        }

        public void setReportCount(int reportCount) {
            this.reportCount = reportCount;
        }

        public String getTextContent() {
            return textContent;
        }

        public void setTextContent(String textContent) {
            this.textContent = textContent;
        }

        public String getIphoto() {
            return iphoto;
        }

        public void setIphoto(String iphoto) {
            this.iphoto = iphoto;
        }

        public String getUname() {
            return uname;
        }

        public void setUname(String uname) {
            this.uname = uname;
        }

        public String getUpname() {
            return upname;
        }

        public void setUpname(String upname) {
            this.upname = upname;
        }

        public String getStaffName() {
            return staffName;
        }

        public void setStaffName(String staffName) {
            this.staffName = staffName;
        }
    }
}
